package com.huabo.system.utils;

import com.huabo.system.mysql.entity.TblAccBookMySql;
import com.huabo.system.oracle.entity.TblAccBook;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class DepartmentUtils {

    public static List<TblAccBook> getAllDepartmentss(List<TblAccBook> tolist) {
        List<TblAccBook> list = new ArrayList<TblAccBook>();
        walkDepartmentListall(tolist,"┣",list);
        return list;
    }

    public static List<TblAccBookMySql> getAllMySqlDepartmentss(List<TblAccBookMySql> tolist) {
        List<TblAccBookMySql> list = new ArrayList<TblAccBookMySql>();
        walkDepartmentListallMySql(tolist,"┣",list);
        return list;
    }

    private static void  walkDepartmentListall(Collection<TblAccBook> toList, String prefix, List<TblAccBook> list){
        for(TblAccBook top:toList){
            //顶级部门
            TblAccBook copy = new TblAccBook();//使用副本，因为原对象在Session中
            copy.setBookid(top.getBookid());
            copy.setBookname(prefix+top.getBookname());
            list.add(copy);
            //子树
            walkDepartmentListall(top.getChildren(),"　"+prefix,list);
        }

    }

    private static void  walkDepartmentListallMySql(Collection<TblAccBookMySql> toList, String prefix, List<TblAccBookMySql> list){
        for(TblAccBookMySql top:toList){
            //顶级部门
            TblAccBookMySql copy = new TblAccBookMySql();//使用副本，因为原对象在Session中
            copy.setBookid(top.getBookid());
            copy.setBookname(prefix+top.getBookname());
            list.add(copy);
            //子树
            walkDepartmentListallMySql(top.getChildren(),"　"+prefix,list);
        }

    }
}
